package com.zerdoor.controller;

import com.zerdoor.model.UserInfo;
import com.zerdoor.pagehelper.PageHelper;
import com.zerdoor.pagehelper.PageInfo;
import com.zerdoor.service.MemRaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xiaoji on 2015/1/9.
 */
@Controller
@RequestMapping("/memrace")
public class MemRaceController {

    @Autowired
    private MemRaceService memRaceService;
    @RequestMapping("toArtistIndex")
    public String toArtistIndex(){
        return "/memrace/artistIndex";
    }

    @RequestMapping("toPrincipalIndex")
    public String toPrincipalIndex(){
        return "/memrace/principalIndex";
    }

    /**
     * FunName:           getArtistRace
     * Description :      会员中心-艺术家我参与的竞赛活动
     * @return String：艺术家仲裁数据
     * @Author:       xiaoji
     * @Create Date: 2015-1-7
     */
    @RequestMapping(value = "/getArtistRace", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getArtistRace(HttpServletRequest request,int page,int rows){
        UserInfo userInfo = (UserInfo)request.getSession().getAttribute("curUser");
        Map<String, Object> map = new HashMap<String,Object>();
        PageHelper.startPage(page, rows);
        List<Map<String, Object>> list = memRaceService.getArtistRace(userInfo.getArtistId());
        PageInfo pageInfo = new PageInfo(list);
        map.put("pageInfo",pageInfo);
        return map;
    }

    /**
     * FunName:           getPrincipalRace
     * Description :      会员中心-委托方我发布的竞赛活动
     * @return String：艺术家仲裁数据
     * @Author:       xiaoji
     * @Create Date: 2015-1-7
     */
    @RequestMapping(value = "/getPrincipalRace", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getPrincipalRace(HttpServletRequest request,int page,int rows){
        UserInfo userInfo = (UserInfo)request.getSession().getAttribute("curUser");
        Map<String, Object> map = new HashMap<String,Object>();
        PageHelper.startPage(page, rows);
        List<Map<String, Object>> list = memRaceService.getPrincipalRace(userInfo.getUserId());
        PageInfo pageInfo = new PageInfo(list);
        map.put("pageInfo",pageInfo);
        return map;
    }

}
